﻿Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Data
Imports System.Xml
Imports System.Xml.XPath
Imports System.Xml.Xsl
Imports System.IO
Imports System.Net
Imports System.Text
Imports BusinessLogic
Imports Yahoo.API

Partial Class Test
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        ClientScript.RegisterClientScriptBlock(Me.GetType, "prototype", [String].Format("<script type=""text/javascript"" src=""{0}""></script>", ResolveClientUrl("~/Javascript/prototype.js")))
        GetNewsSearchWebServiceResults()
    End Sub

    Private Sub GetNewsSearchWebServiceResults()
        If Session("SearchResults") IsNot Nothing Then
            newsRes.DataSource = Session("SearchResults")
            newsRes.DataBind()
        Else
            Dim srch As String = ""
            srch &= ConfigurationManager.AppSettings("RecentNews")

            Dim yahoo As New YahooSearchService

            Dim _SearchResults As New ArrayList()
            Dim Count As Integer = 10
            Dim Offset As Integer = 1

            Dim resultSet As Yahoo.API.NewsSearchResponse.ResultSet
            Try
                Dim YahooApiKey As String = ConfigurationManager.AppSettings("YahooAPIKey").ToString
                resultSet = yahoo.NewsSearch(YahooApiKey, srch, "all", Count, Offset, "rank", "en")

                For Each result As Yahoo.API.NewsSearchResponse.ResultType In resultSet.Result
                    Dim _TempSearchResult As New SearchResult()

                    _TempSearchResult.Url = result.Url
                    If result.Title.Length > 60 Then
                        _TempSearchResult.Title = result.Title.Substring(0, 58) & "..."
                    Else
                        _TempSearchResult.Title = result.Title
                    End If
                    _TempSearchResult.Summary = result.Summary
                    _SearchResults.Add(_TempSearchResult)

                Next
            Catch ex As Exception
            End Try
            Session("SearchResults") = _SearchResults
            newsRes.DataSource = Session("SearchResults")
            newsRes.DataBind()
        End If
    End Sub
    Public Class SearchResult
        Private _Url As String
        Property Url() As String
            Get
                Return _Url
            End Get
            Set(ByVal value As String)
                _Url = value
            End Set
        End Property

        Private _Title As String
        Property Title() As String
            Get
                Return _Title
            End Get
            Set(ByVal value As String)
                _Title = value
            End Set
        End Property

        Private _Summary As String
        Property Summary() As String
            Get
                Return _Summary
            End Get
            Set(ByVal value As String)
                _Summary = value
            End Set
        End Property


        Private _PublishDate As String
        Property PublishDate() As String
            Get
                Return _PublishDate
            End Get
            Set(ByVal value As String)
                _PublishDate = value
            End Set
        End Property

        Private _Thumbnail As String
        Property Thumbnail() As String
            Get
                Return _Thumbnail
            End Get
            Set(ByVal value As String)
                _Thumbnail = value
            End Set
        End Property
    End Class
End Class
